package zhxt.helmet.configurer;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import zhxt.helmet.utils.CameraResultHandler;

@Configuration
@EnableWebSocket
//设置WebSocket, 用于识别结果广播
public class WebSocketConfig implements WebSocketConfigurer {

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(new CameraResultHandler(), "/results-broadcast").setAllowedOrigins("*");
    }

    @Bean
    public WebSocketHandler cameraResultHandler() {
        return new CameraResultHandler();
    }
}

